<template>
    <div class="content">
        <div class="content-div">

            <div class="content-div-left">
                <div  class="content-div-left-first">
                    <div class="content-div-left-header">产品类型</div>
                    <div class="content-div-left-item" v-for="item in catList" :key="item.id" @click="openProduct(item)">{{ item.title }}</div>
                </div>
                <div class="content-div-left-sec" >
                    <div class="content-div-left-header-about">关于我们</div>
                    <div class="content-div-left-item" @click="openAbout('companyId')">
                        公司简介
                        <img src="@/static/engineering5188/company/nav-left.png" alt=""/>
                    </div>
                    <div class="content-div-left-item"  @click="openAbout('certailId')">
                        工商资质
                        <img src="@/static/engineering5188/company/nav-left.png" alt=""/>
                    </div>
                    <div class="content-div-left-item"   @click="openAbout('honerId')">
                        企业荣誉
                        <img src="@/static/engineering5188/company/nav-left.png" alt=""/>
                    </div>
                </div>
            </div>

            <div class="content-div-right">
                <div class="content-div-right-header">
                    <div v-if="!detailFlag">公司相册</div>
                    <div v-if="detailFlag">公司相册</div>
                </div>

                <div class="content-div-product-content" v-if="!detailFlag">
                    <div class="content-div-product">
                        <div class="content-div-product-item" v-for="(item,index) in productList" @click="openDetail(item,index)">
                            <img :src="item.file_path" alt="">
                            <div class="content-div-product-item-text">{{ item.title }}</div>
                        </div>
                    </div>
                    <div class="pageClass" v-if="productList.length > 0">
                        <div class="pageClass-first" @click="LoadFistData">首页</div>
                        <div class="pageClass-Last" @click="LoadLastData">上一页</div>
                        <template v-if="totalPage < 6">
                            <div :class="{ 'pageClass-num': true, 'active': currentPage == 1 }" @click="loadPageData(1)"
                                v-if="totalPage >= 1">1</div>
                            <div :class="{ 'pageClass-num': true, 'active': currentPage == 2 }" @click="loadPageData(2)"
                                v-if="totalPage >= 2">2</div>
                            <div :class="{ 'pageClass-num': true, 'active': currentPage == 3 }" @click="loadPageData(3)"
                                v-if="totalPage >= 3">3</div>
                            <div :class="{ 'pageClass-num': true, 'active': currentPage == 4 }" @click="loadPageData(4)"
                                v-if="totalPage >= 4">4</div>
                            <div :class="{ 'pageClass-num': true, 'active': currentPage == 5 }" @click="loadPageData(5)"
                                v-if="totalPage >= 5">5</div>
                            <div :class="{ 'pageClass-num': true, 'active': currentPage == 6 }" @click="loadPageData(6)"
                                v-if="totalPage >= 6">6</div>
                        </template>
                        <template v-else>
                            <div :class="{ 'pageClass-num': true, 'active': currentPage == 1 }" @click="loadPageData(1)">1
                            </div>
                            <div :class="{ 'pageClass-num': true, 'active': currentPage == 2 }" @click="loadPageData(2)">2
                            </div>
                            <div class="pageShenLue">...</div>
                            <div :class="{ 'pageClass-num': true, 'active': currentPage == totalPage - 1 }"
                                @click="loadPageData(totalPage - 1)">{{ totalPage - 1 }}</div>
                            <div :class="{ 'pageClass-num': true, 'active': currentPage == totalPage }"
                                @click="loadPageData(totalPage)">{{ totalPage }}</div>
                        </template>
                        <div class="pageClass-Last" @click="LoadNextData">下一页</div>
                        <div class="pageClass-first" @click="LoadEndData">末页</div>
                    </div>
                </div>

                <!-- <div  v-if="detailFlag">
                    <div class="detailClass">
                        <div >
                            <div>
                                <img class="logo" :src="productList[currentIndex].file_path" alt=""/>
                            </div>
                            <div>
                                <div class="detailClass-title">{{ productList[currentIndex].title }}</div>
                                <div class="detailClass-label-item">
                                    <span style="color:#747474">工程所在地：</span>
                                    <span>{{ productList[currentIndex].address }}</span>
                                </div>
                                <div class="detailClass-label-item">
                                    <span style="color:#747474">所用材料：</span>
                                    <span>{{ productList[currentIndex].material }}</span>
                                </div>
                                <div class="detailClass-label-item">
                                    <span style="color:#747474">说明：</span>
                                    <span>{{ productList[currentIndex].describe }} </span>
                                </div>
                            </div>
                        </div>
                        <div class="detail-description">
                            <div class="detail-description-name">产品说明</div>
                        </div>
                        <div v-for="item in productList[currentIndex].imageList">
                            <img class="detail-img" :src="item" alt=""/>
                        </div>
                        
                    </div>
                </div> -->
            </div>

        </div>

    </div>
</template>

<script>
import { mapState } from "vuex";
export default {
    computed: {
        ...mapState([
            "userInfo",
        ]),
    },
    data() {
        return {
            detailData: null,
            productList: [],
            totalPage: 0,
            currentPage: 1,
            detailFlag:false,
            currentIndex:0,
            totalCount:0,
            catList:[],
        }
    },
    created() {
        this.getDetail();
        this.getProductList();
        this.getCat();
    },
    methods: {
        openProduct(item){
            this.$router.push({
              path: '/companyInfo/product',
              query: {
                shop_id: this.$route.query.shop_id,
                custom_cat_id: item.id,
              }
            })
        },
        openAbout(item){
          this.$router.push({
            path: '/companyInfo/profile',
            query: {
              shop_id: this.$route.query.shop_id,
              reload: item,
            }
          })
        },
        getCat(){
            this.$httpApi("/api/getProductCustomCatList", {
                limit:10000,
                page:1,
                shop_id:this.$route.query.shop_id
            }, "get").then(res => {
                this.catList = res.data.list;
            })
        },
        getPrice(item){
            if(item.min_price && item.max_price){
                return item.min_price + "~" + item.max_price + "元"
            } else {
                return "暂无报价"
            }
        },
        openDetail(item,index){
            // this.detailFlag = true;
            // this.currentIndex = index;
        },
        getDetail() {
            this.$httpApi("/api/getShopDetail", {
                shop_id: this.$route.query.shop_id
            }, "get").then(res => {
                this.detailData = res.data;
            })
        },
        getProductList() {
            this.$httpApi("/api/getCompanyPhotoList", {
                shop_id: this.$route.query.shop_id,
                page: this.currentPage,
                limit: 12,
                token: this.userInfo.token,
                file_type:1,
            }, "get").then(res => {
                res.data.list.forEach(element => {
                    try {
                        element.imageList = JSON.parse( element.file_path);
                    }catch(e){
                        element.imageList = [{
                            file_url:''
                        }];
                    }
                    
                });
                this.productList = res.data.list;
                this.totalCount = res.data.count;
                this.totalPage = Math.ceil(res.data.count / 10);
            })
        },
        LoadFistData() {
            this.currentPage = 1;
            this.getProductList();
        },
        LoadLastData() {
            if (this.currentPage > 1) {
                this.currentPage--;
                this.getProductList();
            }
        },
        LoadNextData() {
            if (this.currentPage < this.totalPage) {
                this.currentPage++;
                this.getProductList();
            }
        },
        LoadEndData() {
            this.currentPage = this.totalPage;
            this.getProductList();
        },
        loadPageData(val) {
            this.currentPage = val;
            this.getProductList();
        },
        lastProduct(){
            if(this.currentIndex > 0){
                this.currentIndex--;
            } else {
                alertErr('已经是第一个产品了'); 
            }
        },
        NextProduct(){
            if(this.currentIndex < this.productList.length - 1){
                this.currentIndex++;
            } else {
                alertErr('已经是最后一个产品了');
            }
        }
    },
}
</script>

<style scoped lang="less">
.content {
    padding-top: 20px;
    background: #F6F6F6;

}

.content-div {
    width: 1200px;
    margin: 0 auto;
    display: flex;
    padding-bottom: 20px;
}

.content-div-left {
    width: 188px;
    flex-basis: 228px;
    flex-grow: 0;
    /* 禁止放大 */
    flex-shrink: 0;
    /* 禁止缩小 */
    
    margin-right: 20px;
    .content-div-left-first{
        background-color: #FFFFFF;
    }

    .content-div-left-sec{
        margin-top: 20px;
        background-color: #FFFFFF;
    }

    .content-div-left-header-about{
        // background: #000000;
        height: 48px;
        line-height: 48px;
        font-weight: 500;
        font-size: 18px;
        color: #333333;
        border-bottom: 1px solid #E6E6E6;
        margin-left: 24px;
        margin-right: 24px;
    }

    .content-div-left-header {
        background: #000000;
        height: 48px;
        line-height: 48px;
        text-align: center;
        font-weight: bold;
        font-size: 16px;
        color: #FFFFFF;
    }

    .content-div-left-item {
        height: 48px;
        line-height: 48px;
        margin-left: 20px;
        margin-right: 20px;
        font-weight: 500;
        font-size: 14px;
        color: #333333;
        border-bottom: 1px solid #E6E6E6;
        padding-left: 24px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        cursor: pointer;
        img{
            width: 16px;
            height: 12px;
            margin-right: 24px;
        }
    }
}

.content-div-right {
    width: 100%;

    .content-div-right-header {
        height: 48px;
        background-color: #FFFFFF;
        font-weight: 500;
        font-size: 16px;
        color: #333333;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding-left: 24px;
        padding-right: 20px;
    }

    .content-div-right-tips {
        font-weight: 400;
        font-size: 14px;
        color: #999999;
    }
}

.content-div-product-content{
    margin-top: 10px;
    background-color: #FFFFFF;
    padding-bottom: 36px;
}

.content-div-product {
    
    padding: 20px;
    padding-right: 0px;
    padding-top: 0px;
    display: flex;
    justify-content: flex-start;
    flex-wrap: wrap;

    .content-div-product-item {
        width: 211px;
        height: 174px;
        border: 1px solid #E5E5E5;
        margin-right: 20px;
        margin-top: 20px;
        cursor: pointer;

        img {
            width: 100%;
            height: 130px;
        }

        .content-div-product-item-text {
            font-weight: 400;
            font-size: 14px;
            color: #333333;
            line-height: 22px;
            padding: 12px;
        }

    }
}

.company-profile {
    background-color: #fff;
    padding-top: 50px;
    padding-bottom: 62px;

    .company-profile-name {
        font-weight: 500;
        font-size: 36px;
        color: #0A0A0A;
        text-align: center;
    }

    .company-profile-tips {
        font-weight: 400;
        font-size: 16px;
        color: #999999;
        text-align: center;
        margin-top: 8px;
    }

    .company-profile-content {
        width: 1200px;
        margin: 0 auto;
        margin-top: 40px;
        display: flex;
        flex-direction: row;

        img {
            width: 468px;
            height: 343px;
            margin-right: 40px;
        }

        .company-profile-content-txt {
            font-weight: 400;
            font-size: 14px;
            color: #000000;
            line-height: 32px;
            text-align: left;
        }

        .company-profile-btn {
            width: 136px;
            height: 40px;
            border-radius: 24px 24px 24px 24px;
            border: 1px solid #333333;
            font-weight: normal;
            font-size: 14px;
            color: #333333;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-top: 27px;

            img {
                width: 23px;
                height: 15px;
                margin-left: 10px;
                margin-right: 0px;
            }
        }
    }
}

.newProductClass {
    padding-top: 40px;
    padding-bottom: 62px;

    .company-profile-name {
        font-weight: 500;
        font-size: 36px;
        color: #0A0A0A;
        text-align: center;
    }

    .company-profile-tips {
        font-weight: 400;
        font-size: 16px;
        color: #999999;
        text-align: center;
        margin-top: 8px;
    }

    .newProductClass-content {
        width: 1200px;
        margin: 0 auto;
        display: flex;
        position: relative;

        .content-div-product-item {
            width: 224px;
            height: 202px;
            border: 1px solid #E5E5E5;
            margin-right: 20px;
            margin-top: 20px;

            img {
                width: 100%;
                height: 136px;
            }

            .content-div-product-item-text {
                font-weight: 400;
                font-size: 14px;
                color: #000000;
                line-height: 22px;
                padding: 12px;
            }

        }

        .arrowIcon {
            width: 40px;
            height: 40px;
        }

        .arrowIconClass {
            position: absolute;
            top: 78px;
            left: -40px;
        }

        .arrowIconClassRight {
            position: absolute;
            top: 78px;
            right: -40px;
        }
    }
}

.pageClass {
    display: flex;
    margin-top: 26px;
    justify-content: center;

    .pageClass-first {
        width: 40px;
        height: 32px;
        background: #FFFFFF;
        border-radius: 4px 4px 4px 4px;
        border: 1px solid #EEEEEE;
        font-weight: normal;
        font-size: 14px;
        color: #7A7A7A;
        line-height: 32px;
        text-align: center;
        margin-right: 16px;
        cursor: pointer;
    }

    .pageClass-Last {
        width: 69px;
        height: 32px;
        background: #FFFFFF;
        border-radius: 4px 4px 4px 4px;
        border: 1px solid #EEEEEE;
        font-weight: normal;
        font-size: 14px;
        color: #7A7A7A;
        line-height: 32px;
        text-align: center;
        margin-right: 10px;
        cursor: pointer;
    }

    .pageClass-num {
        width: 32px;
        height: 32px;
        background: #FFFFFF;
        border-radius: 4px 4px 4px 4px;
        border: 1px solid #EEEEEE;
        font-weight: normal;
        font-size: 14px;
        color: #7A7A7A;
        line-height: 32px;
        text-align: center;
        margin-right: 10px;
        cursor: pointer;
    }

    .pageShenLue {
        font-weight: normal;
        font-size: 14px;
        color: #7A7A7A;
        margin-right: 10px;
    }

    .active {
        background: #31A41B;
        color: #FFF;
    }
}

.detailClass{
    margin-top: 10px;
    background-color: #FFF;
    padding: 30px;
    
    .logo{
        width: 892px;
        height: 550px;
    }

    .detailClass-title{
        font-weight: 500;
        font-size: 20px;
        color: #000000;
        line-height: 20px;
        margin-top: 24px;
    }

    .detailClass-label-item{
        font-weight: 400;
        font-size: 16px;
        color: #000000;
        line-height: 20px;
        margin-top: 16px;
    }
}

.detail-description{
    height: 48px;
    background: #F9F9F9;
    display: flex;
    margin-top: 20px;
    margin-bottom: 10px;
    .detail-description-name{
        font-weight: 500;
        font-size: 18px;
        color: #000000;
        border-bottom: 3px solid #000000;
        line-height: 45px;
        margin-left: 43px;
    }
}
.detail-img{
    width: 892px;
    height: 395px;
    margin-bottom: 20px;
}
.btn-div{
    display: flex;
    margin-top: 32px;
    align-items: center;
    justify-content: center;
}
.m-l-24{
    margin-left: 24px;
}
.btn{
    width: 133px;
    height: 44px;
    background: #FFFFFF;
    border-radius: 4px 4px 4px 4px;
    border: 1px solid #D4D4D4;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    img {
        width: 20px;
        height: 20px;
        margin-right: 10px;
    }
}
</style>